<?php
class Shelf extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('services/book_shelf_service', 'book_shelf_service');
    }

    public function lists()
    {
        $err = null;
        $lists = $this->book_shelf_service->getShelfList($this->_uid, $err);
        if ( ! is_null($err))
        {
            $this->renderJson($err['errorCode'], $err['errorMessage']);
        }
        $this->renderJson(STATUS_OK, $lists);
    }

    public function add()
    {
        $err = null;
        $novel_id = $this->request_array['novelId'] ?? null;
        $add = $this->book_shelf_service->addNovelToShelf($novel_id, $this->_uid, $err);
        if ( ! is_null($err))
        {
            $this->renderJson($err['errorCode'], $err['errorMessage']);
        }
        $this->renderJson();
    }

    public function delete()
    {
        $err = null;
        $novel_id = $this->request_array['novelId'] ?? null;
        $del = $this->book_shelf_service->removeNovelFromShelf($novel_id, $this->_uid, $err);
        if ( ! is_null($err))
        {
            $this->renderJson($err['errorCode'], $err['errorMessage']);
        }
        $this->renderJson();
    }
}